{% extends "AcmeDemoBundle::base.html.twig" %} {% block javascript %}
<script type="text/javascript">
	$(function(){
		
		$("#addButton").click(function() {
			window.location.href = "{{ path('acme_phongban_input') }}";
        });
		
		$("#success").click(function() {
			$("#success").hide();
        });
		
		logic();
		
	});
	
	function edit(id){
		$("#form").attr("action", "{{ path('acme_phongban_detail') }}" + "/" + id);
        $("#form").submit();
	}
    function del(id, name){
        if(confirm('Bạn có muốn xóa đơn vị/phòng ban ' +name +' này không?' )){
        	$("#form").attr("action", "{{ path('acme_phongban_del') }}" + "/" + id);
            $("#form").submit();
        }
    }
    function logic() {
    	var count = {{count}};
    	count = parseInt(count);
    	var index = {{index}};
    	index = parseInt(index);
    	var html = "";
    	if (index == 1) {
    		html += "<span class='previous-off'>&laquo; Trước</span>";
    	} else {
    		html += "<a href='javascript:previous()' class='previous'>&laquo; Trước</a>";
    	}
        if(count <= 6 ){
        	for(var i=1;i<=count;i++) {
        		if(index == i) {
        			html += "<span class='active'>" + i +"</span>";
        		} else {
        			html += "<a href='javascript:paging(" + i + ")'>" + i + "</a>";
        		}
        	}
        } else if (count > 6 && index < 5) {
        	for(var i=1;i<6;i++) {
                if(index == i) {
                    html += "<span class='active'>" + i +"</span>";
                } else {
                    html += "<a href='javascript:paging(" + i + ")'>" + i + "</a>";
                }
            }
        	 html += "<span class='active'>...</span>";
        	 html += "<a href='javascript:paging(" + count + ")'>" + count + "</a>";
        } else if (count > 6 && index >= count - 4) {
        	html += "<a href='javascript:paging(" + 1 + ")'>" + 1 + "</a>";
        	html += "<span class='active'>...</span>";
        	
            for(var i=count - 4;i<= count;i++) {
                if(index == i) {
                    html += "<span class='active'>" + i +"</span>";
                } else {
                    html += "<a href='javascript:paging(" + i + ")'>" + i + "</a>";
                }
            }
            
        } else {
        	
        	var sub2 = index - 2;
        	var sub1 = index - 1;
        	var add1 = index + 1;
        	var add2 = index + 2;
        	html += "<a href='javascript:paging(" + 1 + ")'>" + 1 + "</a>";
            html += "<span class='active'>...</span>";
            
            html += "<a href='javascript:paging(" + sub2 + ")'>" + sub2 + "</a>";
            html += "<a href='javascript:paging(" + sub1 + ")'>" + sub1 + "</a>";
            html += "<span class='active'>" + index +"</span>";
            html += "<a href='javascript:paging(" + add1 + ")'>" + add1 + "</a>";
            html += "<a href='javascript:paging(" + add2 + ")'>" + add2 + "</a>";
            
             html += "<span class='active'>...</span>";
             html += "<a href='javascript:paging(" + count + ")'>" + count + "</a>";
        }
        
        if (index >= count) {
            html += "<span class='next-off'>Tiếp &raquo;</span>";
        } else {
            html += "<a href='javascript:next()' class='next'>Tiếp &raquo;</a>";
        }
        $("#pagination").html(html);
    }
    function paging(index){
    	$("#form").attr("action", "{{ path('acme_phongban_list') }}" + "/" + index);
        $("#form").submit();
    }
    function previous(){
    	var index = {{index}};
    	index = parseInt(index) - 1;
    	$("#form").attr("action", "{{ path('acme_phongban_list') }}" + "/" + index);
        $("#form").submit();
    }
    function next(){
    	var index = {{index}};
        index = parseInt(index) + 1;
    	$("#form").attr("action", "{{ path('acme_phongban_list') }}" + "/" + index);
        $("#form").submit();
    }
    
</script>
{% endblock %} {% block content %}
<div class="grid_16">
	<!-- TABS START -->
	<div id="tabs">
		<div class="container">
			<ul>
			<li><a href="{{ path('acme_Nhom_list') }}/1"><span>Nhóm</span></a></li>
				<li><a href="{{ path('acme_phongban_list') }}/1" class="current"><span>Đơn vị/phòng ban
                            </span></a></li>
                <li><a href="{{ path('acme_chucvu_list') }}/1"><span>Chức vụ</span></a></li>
				<li><a href="{{ path('acme_TrinhDo_list') }}/1"><span>Trình độ</span></a></li>
				<li><a href="{{ path('acme_ThiDua_list') }}/1"><span>Thi đua</span></a></li>
				<li><a href="{{ path('acme_Chung_detail') }}/1"><span>Hệ thống</span></a></li>
				<li><a href="{{ path('acme_Lydonghiviec_list') }}/1"><span>Lý do nghỉ việc</span></a></li>
			</ul>
		</div>
	</div>
	<!-- TABS END -->
</div>
<div class="grid_16" id="content">

	<div class="grid_9">
		<h1 class="dashboard">Danh sách đơn vị/phòng ban</h1>
	</div>
	<div id="eventbox" class="grid_6">
	<a class="button" id="addButton">
<span>Thêm đơn vị/phòng ban</span>
</a>
	</div>
	{% if thongbao %}
		<div class="grid_15">
	<p id="success" class="info">
	<span class="info_inner">Cập nhật thành công !</span>
	</p>
	</div>
	{% endif %}
	<div class="grid_16">
		<form id="form" method="post">
			<table width="90%" cellpadding="0" cellspacing="0" id="box-table-a"
				summary="Employee Pay Sheet">
				<thead>
					<tr>
						<th width="20" scope="col">STT</th>
						<th width="50" scope="col">Mã</th>
						<th width="200" scope="col">Tên</th>
						<th width="400" scope="col">Địa chỉ</th>
						<th width="100" scope="col">Nhóm</th>
						<th width="90" scope="col"></th>
					</tr>
				</thead>
				<tbody>
					{% for phongban in listPhongBan %}
					<tr>

						<td>{{loop.index + 10*(index-1)}}</td>
						<td>{{phongban.ma}}</td>
						<td>{{phongban.ten}}</td>
						<td>{{phongban.diachi}}</td>
						<td>
						      {% if phongban.nhomid.ten is defined %}
							    {{phongban.nhomid.ten}}
							{% endif %}
						</td>
						<td width="90"><a class="edit_icon" style="cursor: pointer;"
							onclick="edit({{phongban.id}})" title="Edit"></a> <a style="cursor: pointer;"
							class="delete_icon" onclick="del({{phongban.id}},'{{phongban.ten}}')" title="Delete"></a></td>
					</tr>
					{% endfor %}


					<tr class="footer">
						<td colspan="4"><!--  PAGINATION START  -->
                            <div id="pagination" class="pagination">
                                
                            </div> <!--  PAGINATION END  --></td>
						<td align="right">&nbsp;</td>
						
					</tr>
				</tbody>
			</table>
		</form>
	</div>


</div>
{% endblock %}
